'use strict'
let Koa = require('koa');
let bodyparser = require('koa-bodyparser');
let stricts = require('koa-static');
let temp = require('./main');
let controllers = require('./controllers');

let models = require('./models');
let session = require('koa-session');
const config = require('./rearend/config');
let app = new Koa();

//处理静态文件
app.use(stricts(__dirname + '/static'));

app.keys = ['ppz']; /** cookie的签名 */
  const CONFIG = {
    key: 'koa:sess', /** 默认 */
    maxAge: 86400000, /** cookie的过期时间 【需要修改】*/
    overwrite: true, /** (boolean) can overwrite or not (default true) 没有效果 默认*/
    httpOnly: true, /** true表示只有服务器端可以获取cookie*/
    signed: true, /** 默认 签名 */
    rolling: false, /** 在每次请求时强行设置 cookie,这将重置 cookie 过期时间(默认：false) 【需要修改】*/
    renew: true, /** (boolean) renew session when session is nearly expired 【需要修改】*/
  }
  app.use(session(CONFIG, app));

//引入中间件
app.use(bodyparser());
//注册中间键
app.use(temp);
//注册自定义路由
app.use(controllers());


 (async () => {
         await models.sync();
 })()

let pron = 5071;

app.listen(pron);

console.log(`http://127.0.0.1:${pron}`);